package com.thermofisher.controller;

import com.thermofisher.beans.*;
import com.thermofisher.service.ProjectService;
import com.thermofisher.utils.Result;
import com.thermofisher.utils.ResultEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author py
 * @since 2020-01-13
 */
@RestController
@RequestMapping("/project")
public class ProjectController
{
    @Autowired
    private ProjectService projectService;

    @PostMapping("/getProjectList")
    public Result getProjectList(@RequestBody Argument argument)
    {
        ProjectData projects = projectService.getProjectList(argument);
        Result result = new Result(String.valueOf(HttpStatus.OK.value()),
                                   HttpStatus.OK.getReasonPhrase(),
                                   projects);
        return result;
    }

    @PostMapping("/getProjectDetails")
    public Result getProjectDetails(@RequestBody Argument argument)
    {
        Result result = new Result();
        String projectNo = argument.getProjectNo();
        String userId = argument.getUserId();
        if (StringUtils.isBlank(projectNo))
        {
            result.setCode(String.valueOf(ResultEnum.CODE_502.getCode()));
            result.setMsg(ResultEnum.CODE_502.getMsg());
        }
        ProjectDetails projectDetails = projectService.getProjectDetails(projectNo, userId);
        result.setCode(String.valueOf(HttpStatus.OK.value()));
        result.setMsg(HttpStatus.OK.getReasonPhrase());
        result.setData(projectDetails);
        return result;
    }

    @PostMapping("/getProjectInfo")
    public Result getProjectInfo(@RequestBody Argument argument)
    {
        Result result = new Result();
        String projectNo = argument.getProjectNo();
        String userId = argument.getUserId();
        if (StringUtils.isBlank(projectNo))
        {
            result.setCode(String.valueOf(ResultEnum.CODE_502.getCode()));
            result.setMsg(ResultEnum.CODE_502.getMsg());
        }
        ProjectDetails projectDetails = projectService.getProjectInfo(projectNo, userId);
        result.setCode(String.valueOf(HttpStatus.OK.value()));
        result.setMsg(HttpStatus.OK.getReasonPhrase());
        result.setData(projectDetails);
        return result;
    }

    @PostMapping("/getProjectMember")
    public Result getProjectMember(@RequestBody Argument argument)
    {
        Result result = new Result();
        String projectNo = argument.getProjectNo();
        String userId = argument.getUserId();
        if (StringUtils.isBlank(projectNo))
        {
            result.setCode(String.valueOf(ResultEnum.CODE_502.getCode()));
            result.setMsg(ResultEnum.CODE_502.getMsg());
        }
        ProjectDetails projectDetails = projectService.getProjectMember(projectNo, userId);
        result.setCode(String.valueOf(HttpStatus.OK.value()));
        result.setMsg(HttpStatus.OK.getReasonPhrase());
        result.setData(projectDetails);
        return result;
    }

    @PostMapping("/getProjectAmount")
    public Result getProjectAmount(@RequestBody Argument argument)
    {
        Result result = new Result();
        String projectNo = argument.getProjectNo();
        String userId = argument.getUserId();
        if (StringUtils.isBlank(projectNo))
        {
            result.setCode(String.valueOf(ResultEnum.CODE_502.getCode()));
            result.setMsg(ResultEnum.CODE_502.getMsg());
        }
        ProjectDetails projectDetails = projectService.getProjectAmount(projectNo, userId);
        result.setCode(String.valueOf(HttpStatus.OK.value()));
        result.setMsg(HttpStatus.OK.getReasonPhrase());
        result.setData(projectDetails);
        return result;
    }

    @PostMapping("/getProjectProduct")
    public Result getProjectProduct(@RequestBody Argument argument)
    {
        Result result = new Result();
        String projectNo = argument.getProjectNo();
        String userId = argument.getUserId();
        if (StringUtils.isBlank(projectNo))
        {
            result.setCode(String.valueOf(ResultEnum.CODE_502.getCode()));
            result.setMsg(ResultEnum.CODE_502.getMsg());
        }
        ProjectDetails projectDetails = projectService.getProjectProduct(projectNo, userId);
        result.setCode(String.valueOf(HttpStatus.OK.value()));
        result.setMsg(HttpStatus.OK.getReasonPhrase());
        result.setData(projectDetails);
        return result;
    }
// 下拉框项目类型
    @GetMapping("/getProjectFilter")
    public Result getProjectFilter()
    {
        ProjectFilter projectFilter = projectService.getProjectFilter();
        Result result = new Result(String.valueOf(HttpStatus.OK.value()),
                                   HttpStatus.OK.getReasonPhrase(),
                                   projectFilter);
        return result;
    }
//项目类型的子类型
    @GetMapping("/getProjectSubFilter")
    public Result getProjectSubFilter(String id)
    {
        ProjectFilter projectFilter = projectService.getProjectSubFilter(id);
        Result result = new Result(String.valueOf(HttpStatus.OK.value()),
                                   HttpStatus.OK.getReasonPhrase(),
                                   projectFilter);
        return result;
    }
//查询项目
    @PostMapping("/getProjectWithFilter")
    public Result getProjectWithFilter(@RequestBody SearchProject searchProject)
    {
        ProjectData projects = projectService.getProjectWithFilter(searchProject);
        Result result = new Result(String.valueOf(HttpStatus.OK.value()),
                                   HttpStatus.OK.getReasonPhrase(),
                                   projects);
        return result;
    }

}

